
Ext.namespace("Ext.milan.pagejs.page_pubInfo");
Ext.milan.pagejs.page_pubInfo.userWin = null;
Ext.milan.pagejs.page_pubInfo.subWin = null;
Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION = "pubInfo";
var selectPostionTree = null;
Ext.milan.pagejs.page_pubInfo.docLoadBeforeCallBack = function() {
};

Ext.milan.pagejs.page_pubInfo.docOnReadyCallback = function() {

};

Ext.milan.pagejs.page_pubInfo.changeJl = function(zt){
	var lbContaniner = $("lb");
	if(zt != ""){
		Milan.ajax.request( {
			url : "pubData/getSubList.do?pid=" + zt.value,
			success : function(response, option) {
				lbContaniner.innerHTML = "";
				var oOption = new Option('请选择','');
				lbContaniner.options.add(oOption);
				if(response&&response.responseText){
					var data = eval("("+response.responseText+")");
					var res = data.root;
					for(var i=0;i<res.length;i++){
						var oOption = new Option(res[i].name,res[i].id);
						lbContaniner.options.add(oOption);
					}
				}
			},
			method : "POST"
		});
	}else{
		cplbContaniner.innerHTML = "";
		var oOption = new Option('请选择','');
		cplbContaniner.options.add(oOption);
	}
};

Ext.milan.pagejs.page_pubInfo.addAttachment=function(divId,fileInputId){
	var id=new Date().getTime();
	var fileName = $(fileInputId).value.split("\\");
	var fileName = fileName[fileName.length-1];
	var operations ='<a href="javascript:void(0);"  title="点击删除本条附件"  onclick="Ext.milan.pagejs.page_pubInfo.deleteAttach(\''+id+'\',\''+fileInputId+'\')"><img src="'+Milan.skinType+'images/icons/ico-delete.gif" /></a>'
	var div1=document.createElement('DIV');
	div1.setAttribute('fileid',fileInputId);	
	div1.innerHTML = "&nbsp;"+fileName+operations;
	div1.id=id;
	div1.style.cssFloat="left";
	div1.style.styleFloat="left";
	$(divId).appendChild(div1);
};
/**
 * 删除通知中的附件
 */
Ext.milan.pagejs.page_pubInfo.deleteAttach = function(id,fid)
{
	if ($(fid) && $(fid).tagName && $(fid).type && $(fid).tagName.toUpperCase() == "INPUT" && $(fid).type.toUpperCase() == "FILE") {
		$(fid).remove();
	}
	if($(id)&&$(id).getAttribute("fileid")&&$(id).getAttribute("fileid")==fid){
		$(id).remove();
	}
}
/**
 * 关闭子弹出窗口
 */
Ext.milan.pagejs.page_pubInfo.closeSubWin = function() {
	Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_pubInfo.subWin);
};

/**
 * 关闭弹出窗口
 */
Ext.milan.pagejs.page_pubInfo.closeWin = function(winName) {
	if(winName){
		if(winName=='inactivateConsignerWin')
			inactivateConsignerWin.closeDialog();
	}
	else
		Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_pubInfo.userWin);
};

/*------------------------ private methods -----------------------*/

/**
 * 查询所有
 */
Ext.milan.pagejs.page_pubInfo._search = function() {
	Ext.milan.pagejs.common_utils.query(false, "pubInfo/list.do");
};

Ext.milan.pagejs.page_pubInfo._formCheck = function(frm) {
	function focusElement(el) {
		if(el.focus)
			el.focus();
	};
	if(frm.bt.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "标题 不能为空！");
		return false;
	}
	if(frm.zt.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "主题 不能为空！");
		return false;
	}
	if(frm.lb.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "类别 不能为空！");
		return false;
	}
	if(frm.fbbm.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "发布部门 不能为空！");
		return false;
	}
	return true;
};

/**
 * 保存信息
 */
Ext.milan.pagejs.page_pubInfo._saveInfo = function(formId) {
	if(!Ext.milan.pagejs.page_pubInfo._formCheck($(formId)))
		return;
		
	/*
	var selectedUsers = $("selected_users_in_poa");
	for(var i = 0; i < selectedUsers.length; i++) {
		selectedUsers[i].selected = true;
	}
	*/
	
	Milan.ajaxutility.formSubmit({
		form:formId,
		success:function(response)
		{
			Ext.milan.pagejs.page_pubInfo.closeWin();
			Ext.milan.pagejs.page_pubInfo.query();
		}
	});
};

/**
 * 条件查询列表
 */
Ext.milan.pagejs.page_pubInfo.query = function() {
	Milan.pagejs.page_index.updateCurrentTabByForm("query_pubInfo_list_form");
};

/**
 * 显示新建表单
 */
Ext.milan.pagejs.page_pubInfo.showAddForm = function() {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/create.do";
	Ext.milan.pagejs.page_pubInfo.userWin = Milan.commonutils.createModelPop({
		title:"新建", 
		url:url,
		width:850
	});
};

Ext.milan.pagejs.page_pubInfo.showAddTzggForm = function() {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/createTzgg.do";
	Ext.milan.pagejs.page_pubInfo.userWin = Milan.commonutils.createModelPop({
		title:"新建", 
		url:url,
		width:850
	});
};

Ext.milan.pagejs.page_pubInfo.showAddGzzdForm = function() {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/createGzzd.do";
	Ext.milan.pagejs.page_pubInfo.userWin = Milan.commonutils.createModelPop({
		title:"新建", 
		url:url,
		width:850
	});
};

/**
 * 显示编辑表单
 * 
 * @param ID
 */
Ext.milan.pagejs.page_pubInfo.showEditForm = function(id) {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/edit.do?id=" + id;
	Ext.milan.pagejs.page_pubInfo.userWin = Milan.commonutils.createModelPop({
		title:"编辑",
		url:url,
		width:850
	});
};

Ext.milan.pagejs.page_pubInfo.showClEditForm = function(id) {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/editTop.do?id=" + id;
	Ext.milan.pagejs.page_pubInfo.userWin = Milan.commonutils.createModelPop({
		title:"编辑",
		url:url,
		width:350
	});
};

Ext.milan.pagejs.page_pubInfo.editTop = function(formId) {
	Milan.ajaxutility.formSubmit({
		form:formId,
		success:function(response)
		{
			Ext.milan.pagejs.page_pubInfo.closeWin();
			Ext.milan.pagejs.page_pubInfo.query();
		}
	});
};

Ext.milan.pagejs.page_pubInfo.showEditTzggForm = function(id) {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/editTzgg.do?id=" + id;
	Ext.milan.pagejs.page_pubInfo.userWin = Milan.commonutils.createModelPop({
		title:"编辑",
		url:url,
		width:850
	});
};

Ext.milan.pagejs.page_pubInfo.showEditGzzdForm = function(id) {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/editGzzd.do?id=" + id;
	Ext.milan.pagejs.page_pubInfo.userWin = Milan.commonutils.createModelPop({
		title:"编辑",
		url:url,
		width:850
	});
};

/**
 * 保存新建用户信息
 */
Ext.milan.pagejs.page_pubInfo.save = function(formId) {
	Ext.milan.pagejs.page_pubInfo._saveInfo(formId);
};

/**
 * 保存编辑后的信息
 */
Ext.milan.pagejs.page_pubInfo.edit = function(formId) {
	Ext.milan.pagejs.page_pubInfo._saveInfo(formId);
};

Ext.milan.pagejs.page_pubInfo.deleteForm = function(id) {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/delete.do?id=" + id;
	new Milan.widget.ConfirmDialog("确认信息", "确认要删除该信息吗？", {
		confirmCallback: function() {
			Milan.ajaxutility.formSubmit({
				url: url,
				method: 'post',
				success: function(response, option)
				{
					Ext.milan.pagejs.page_pubInfo.query();
				}
			});
		}
	});	
};


/**
 * 查看详情
 * 
 * @param entityId 用户ID
 */
Ext.milan.pagejs.page_pubInfo.viewDetail = function(entityId) {
	var url = Ext.milan.pagejs.page_pubInfo.REQUEST_ACTION + "/show.do?id=" + entityId;
	Ext.milan.pagejs.page_pubInfo.userWin = Milan.commonutils.createModelPop({
		title:"详细信息",
		url:url,
		width:850
	});
};


/**
 * 显示“选择人员”弹出框
 */
Ext.milan.pagejs.page_pubInfo.selectUsers = function(selectItemId) {

	new Milan.widget.Selector({
		orgType:"12",
		title:"选择人员",
		deptUrl:"dept/selectDept.do?",
		quickSelectUrl:"user/quickUser.do?",
		searchUrl:"user/searchUser.do?",
		isRecentEnable :false,
		isUpdateRecentEnable :false,
		isDeptSelEnable:true
	},
	true,
	{
		onSelectedCallBack : function(arr)
		{
			var selectItem = $(selectItemId);
			var isExisted = false;
			if(arr != null && arr.length > 0) {
				for (var i = 0; i<arr.length; i++) {
					for (var x = 0; x < selectItem.length; x++) {
						if (arr[i].id == selectItem[x].value) {
							isExisted=true;
							break;
						}	
					}
					
					if (!isExisted) {
						var optionEl = document.createElement("OPTION");
						optionEl.text = arr[i].name;
						optionEl.value = arr[i].id;
						selectItem.options.add(optionEl);
					}
						
					isExisted = false;
				}
			}  
			
			Ext.milan.pagejs.page_pubInfo.displayBtn(selectItem);
		}
	});
};

Ext.milan.pagejs.page_pubInfo.displayBtn = function(selectItem) {
	if(selectItem.length > 0) {
		Element.show('del_user_in_poa_btn');
	}else {
		Element.hide('del_user_in_poa_btn');
	}
}

/**
 * 移除用户
 */
Ext.milan.pagejs.page_pubInfo.removeUser = function() {
	var selectedUsers = $("selected_users_in_poa");
	if(selectedUsers.length == 0)
		return;
				
	var delUserArray = [];
	for(var i = 0; i < selectedUsers.length; i++) {
		if(selectedUsers[i].selected) {
			delUserArray.push(selectedUsers[i]);
		}
	}
	
	if(selectedUsers.selectedIndex ==-1){
		new Milan.widget.Dialog("信息提示","请选择要移除的人员!");
		return;
	}
			
	for(var j = 0; j < delUserArray.length; j++) {
		selectedUsers.removeChild(delUserArray[j]);
	}
	
	if(selectedUsers.length == 0) 
		Element.hide('del_user_in_poa_btn');
};